package com.ls.lsojcodesandbox.config;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.api.model.Container;

import java.io.IOException;
import java.util.List;


public class DockerConfig {
    public static void main(String[] args) {
// 创建 Docker 客户端
        DockerClient dockerClient = DockerClientBuilder.getInstance().build();

        // 列出所有容器（包括运行中和已停止的）
        List<Container> containers = dockerClient.listContainersCmd()
                .withShowAll(true)
                .exec();

        for (Container container : containers) {
            System.out.printf("ID: %s, Image: %s, Command: %s, Status: %s%n",
                    container.getId(),
                    container.getImage(),
                    container.getCommand(),
                    container.getStatus());
        }

        // 关闭客户端
        try {
            dockerClient.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
